<?php

namespace App\Http\Validate\WorkOrder\FunctionOpen;

use App\Enums\WorkOrder\OrderEnum;
use App\Http\Validate\AbstractBaseValidate;
use App\Models\WorkOrder\FunctionOpen\WorkOrderFunctionOpenRecordModel;
use App\Models\WorkOrder\WorkOrderApplyMainModel;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class FunctionOpenValidate extends AbstractBaseValidate
{
    public function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [
            "type" => "required|int|in:" . enumTransToRules(OrderEnum::FUNCTION_OPEN)
        ];
    }

    public function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    public function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    public function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function formContentValidate(array $params)
    {
        return self::getInstance()->validate(["type"], $params);
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function saveFieldValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id", "field", "value"],
            $params,
            [
                "id"    => Rule::exists("work_order_apply_content", "id"),
                "field" => "required|string|min:0|max:48",
                "value" => "required"
            ]
        );
    }


    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function saveFieldsValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id", "formFields"],
            $params,
            [
                "id"         => Rule::exists("work_order_apply_content", "id"),
                "formFields" => "required|array|min:0"
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function submitFormValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id"],
            $params,
            ["id" => Rule::exists("work_order_apply_content", "id")]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function fyRegionBankValidate(array $params)
    {
        return self::getInstance()->validate(
            ["regionBankCode", "bankTypeCode", "parentId"],
            $params,
            [
                "regionBankCode" => "required|string",
                "bankTypeCode"   => "required|string",
                "parentId"       => "string",
            ]
        );
    }
}
